/*
 * CS_MARKET_MY_ITEM_LIST_V2.cpp
 *
 *  Created on: 2013. 12. 23.
 *      Author: mega
 */

#include "../../Command.h"
#include "../../User.h"
#include "../../NLogic/Trade.h"

namespace ProjectZ { namespace NCommand {

void Command::CS_MARKET_MY_ITEM_LIST_V2(User * pUser, ::Network::Packet * pPacket)
{
	PREPARE_PACKET;

	NLogic::Trade * pTrade = pUser->GetTrade();
	if (NULL == pTrade)
	{
		DEBUGLOG("CS_MARKET_MY_ITEM_LIST_V2 : pTrade is NULL!");
		return;
	}

	time_t curDate	= time(NULL);

	::Network::Packet * pAck = ::Network::GETPACKETPOOL()->SEND_NEW();
	*pAck << static_cast<int16_t>(ACK_OK);
	*pAck << static_cast<uint16_t>(pTrade->GetTradeItemTree().size());
	*pAck << static_cast<uint8_t>(pTrade->GetTradeItemTree().size());

	NLogic::Trade::REGISTITEMTREE::const_iterator citer = pTrade->GetTradeItemTree().begin();

	for (; citer != pTrade->GetTradeItemTree().end(); ++citer)
	{
		*pAck << citer->second->GetTradeSeq();
		*pAck << static_cast<uint8_t>(citer->second->GetData().item.class_type);
		*pAck << static_cast<uint8_t>(citer->second->GetData().item.sub_type);
		*pAck << static_cast<uint16_t>(citer->second->GetData().item.tid);
		*pAck << static_cast<uint8_t>(citer->second->GetData().item.cur_refine_step);
		*pAck << static_cast<uint8_t>(citer->second->GetData().item.level);
		*pAck << static_cast<uint8_t>(citer->second->GetData().item.quality);
		*pAck << static_cast<uint8_t>(citer->second->GetData().item.open_upgrade_stone_slot);
		*pAck << static_cast<uint8_t>(citer->second->GetData().item.evolve_step);
		*pAck << static_cast<uint8_t>(citer->second->GetData().item.evolve_max);
		*pAck << static_cast<uint8_t>(citer->second->GetData().item.eff_type[0]);
		*pAck << static_cast<uint16_t>(citer->second->GetData().item.eff_value[0]);
		*pAck << static_cast<uint32_t>(citer->second->GetData().item_price);

		int remainHour = 0;
		if ( (citer->second->GetData().limit_date - curDate) > 0)
			remainHour = (citer->second->GetData().limit_date - curDate) / 3600;

		*pAck << static_cast<uint8_t>(remainHour);
		*pAck << static_cast<int8_t>(citer->second->GetData().item.set_type);
	}

	pAck->MakePacket(CMD_SC_MARKET_MY_ITEM_LIST_V2);
	pUser->Send(pAck);

}

} /*NCommand*/ } /*ProjectZ*/


